use std::thread::sleep;
use std::time::Duration;

pub struct Task {
    detail: TaskType,
}




type TaskType = Box<dyn FnOnce() + Send +Sync + 'static>;

impl Task {
    pub fn new<F>(f:F) ->Self
        where F: FnOnce() + Send + Sync + 'static,  {
        Task {
            detail: Box::new(f),
        }
    }

    pub fn task(self, worker_name:String) -> TaskType {
        println!("the task is handled by worker: {}" , worker_name);
        //sleep(Duration::new(1,0));
        self.detail
    }
}

unsafe impl Send for Task {}

unsafe impl Sync for Task{}

